package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Permission;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.IPermissionService;
import cn.wolfcode.rbac.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Description TODO
 * @ClassName PermissionController
 * @Author luhui
 * @date 2020.06.13 12:58
 * @version: 1.0
 */

@Controller
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/permission/list")
    @RequiredPermission(values = {"权限列表","permission:list"})
    public String list(Model model, QueryObject queryObject){
        model.addAttribute("result",permissionService.query(queryObject));
        return "permission/list";
    }

    @RequestMapping("/permission/delete")
    @RequiredPermission(values = {"权限删除","permission:delete"})
    public String delete(Long id){
        permissionService.delete(id);
        return "redirect:/permission/list.do";
    }

   /* @RequestMapping("/permission/input")
    public String input(Model model,Long id){
        if (id != null){
            model.addAttribute("entity",permissionService.get(id));
        }
        return "permission/input";
    }

    @RequestMapping("/permission/saveOrUpdate")
    public String saveOrUpdate(Permission permission){
        permissionService.saveOrUpdate(permission);
        return "redirect:/permission/list.do";
    }*/

    @RequestMapping("/permission/reload")
    @RequiredPermission(values = {"权限加载","permission:reload"})
    public String reload(){
        permissionService.reload();
        return "redirect:/permission/list.do";
    }
}